#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
	ofstream gNseURLFile;
	gNseURLFile.open("NseURLFile.txt");
	
	const char gCommonURL[]="http://www.nseindia.com/content/historical/EQUITIES/2007/JAN/cm";

	//Example http://www.nseindia.com/content/historical/EQUITIES/2011/APR/cm13APR2011bhav.csv.zip

	const char* postfixyear[5]={"2007","2008","2009","2010","2011"};

	const char postfixstr[]="JAN2007bhav.csv.zip";
	
	const unsigned int datesinmonth[12]= {31,28,31,30,31,30,31,31,30,31,30,31};

	unsigned int lenoffinalURL=strlen(gCommonURL)+3+strlen(postfixstr);
	unsigned int dateseekinfinalURL=strlen(gCommonURL);
	char *finalURL=new char[lenoffinalURL];

	strcpy(finalURL,gCommonURL);
	strcat(finalURL,"00");
	strcat(finalURL,postfixstr);
	finalURL[lenoffinalURL]='\0';

	//Monday 1st jan,2007

	const char* dates[31]={"01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"};
	gNseURLFile<<"const char* gCommonURL[]={";

	if (gNseURLFile.is_open())
	{
		for(int i=0,j=0,k=0;i<31;++i)
		{
			if(j<5){
			finalURL[dateseekinfinalURL]=dates[i][0];
			finalURL[dateseekinfinalURL+1]=dates[i][1];
			gNseURLFile<<"_T(\""<<finalURL<<"\")"<<","<<"\n";
			++j;
			}
			else
			{
				if(k<1)
				{
					++j;
					++k;
				}
				else
				{
					j=0;
					k=0;
				}
			}

		}
		gNseURLFile<<"};";

	}
	gNseURLFile.close();

}
